package com.example.controller;

import com.example.domain.AjaxResult;
import com.example.netty.ChannelMap;
import com.example.util.ConvertCode;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.springframework.web.bind.annotation.*;


/**
* @author WXY
* @date 2022/6/29 20:44
*/
@RestController
@RequestMapping("/send")
public class SendMessageController {


   @PostMapping("/message")
   @ResponseBody
   public AjaxResult base64ToImageUrl() {
       try
       {

           for (Channel channel:ChannelMap.getChannelMap().values()) {
               System.out.println("channel = " +channel);
               //Netty需要用ByteBuf传输
               ByteBuf bufff = Unpooled.buffer();
               //对接需要16进制
               bufff.writeBytes(ConvertCode.hexString2Bytes("1103006000018684"));
               channel.writeAndFlush(bufff);
           }
           AjaxResult ajax = AjaxResult.success();
           return ajax;
       }
       catch (Exception e)
       {
           e.printStackTrace();
           return AjaxResult.error(e.getMessage());
       }
   }


}
